#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

using GameFramework.ScreenSystem;

namespace GameFramework
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class GameManager : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ScreenSystem.ScreenManager screenManager;
        GameComponents.FPSCounter FpsCounter;
        
        public static AudioSystem.AudioManager AudioManager;

        // Setup the Storage Systems
        public static StorageSystem.StorageManager StorageManager;

        public static GameComponents.BloomComponent bloom;

        public GameManager()
        {
            graphics = new GraphicsDeviceManager(this);

            graphics.PreferredBackBufferWidth = 853;
            graphics.PreferredBackBufferHeight = 480;

            // Create the screen manager component.
            screenManager = new ScreenSystem.ScreenManager(this);

            Components.Add(screenManager);

            // Add the Framerate Game Component
            FpsCounter = new GameFramework.GameComponents.FPSCounter(this, GameComponents.FPSOutput.Game);
            FpsCounter.DrawOrder = 100;
            Components.Add(FpsCounter);

            // Create the audio manager component.
            AudioManager = new AudioSystem.AudioManager(
                            @"Content/Audio/GameFramework.xgs",
                            @"Content/Audio/Wave Bank.xwb",
                            @"Content/Audio/Sound Bank.xsb", this); 
            Components.Add(AudioManager);

            // Setup the Storage Manager

            StorageManager = new GameFramework.StorageSystem.StorageManager(this, "GameFramework", "GameOptions.vrd", "PlayerData.vrd");
            Components.Add(StorageManager);

            bloom = new GameFramework.GameComponents.BloomComponent(this);
            bloom.DrawOrder = 99;
            Components.Add(bloom);
        }


        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            
            base.Initialize();

            // Add the UI category that groups all the UI sound effects
            AudioManager.AddCategory("UI");

            // Add the music cues that will be used for each known GameScreen.
            AudioManager.Add("MainMenuMusic");
            AudioManager.Add("OptionsMenuMusic");
            AudioManager.Add("LoadingMenuMusic");
            AudioManager.Add("PlayScreenMusic");
            AudioManager.Add("PauseMessageBoxMusic");
            AudioManager.Add("QuitMessageBoxMusic");

            // TODO: Add any music cues that have been added later to the XACT project here.

            // Add the sound effects that will be used for UI interactions.
            AudioManager.Add("ButtonClick");
            AudioManager.Add("ButtonBack");
            AudioManager.Add("ButtonToButton");
            AudioManager.Add("PageToPage");
            AudioManager.Add("PageTurn");

            // TODO: Add any sound effects that have been added later to the XACT project here.

            // Load in the Game Options.
            //gameOptions = storageManager_old.LoadGameData("GameFramework", GameManager.StorageManager.GameOptionsFilename);
            StorageManager.LoadGameOptions();

            // Activate the first screens.
            screenManager.AddScreen(new BackgroundScreen());
            screenManager.AddScreen(new MainMenuScreen("MainMenuMusic", MenuTransition.Transition4));

            // TODO: Add your initialization logic here

        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.Black);

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}
